#include "widget.h"
#include "ui_widget.h"
#include <QDebug>
//QLineEdit单行输入框控件-代码示例-用户输入信息表
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    //创建对象并初始化
    creater();

    //姓名
    //提示信息
    line_name->setPlaceholderText("请输入姓名");
    //添加清除按钮
    line_name->setClearButtonEnabled(true);

    //密码
    //提示信息
    line_password->setPlaceholderText("请输入密码");
    //添加清除按钮
    line_password->setClearButtonEnabled(true);
    //设置回显模式  密码模式
    line_password->setEchoMode(QLineEdit::Password);

    //电话
    //提示信息
    line_phone->setPlaceholderText("请输入电话");
    //添加清除按钮
    line_phone->setClearButtonEnabled(true);
    //设置密码填写方式 按照000-0000-0000这种模式输入
    line_phone->setInputMask("000-0000-0000");

    //设置点击button按钮后，clicked信号与槽函数绑定
    connect(button_submit,&QPushButton::clicked,this,&Widget::handler);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::creater()
{
    label_name=new QLabel(this);
    label_password=new QLabel(this);
    label_sex=new QLabel(this);
    label_phone=new QLabel(this);

    line_name=new QLineEdit(this);
    line_password=new QLineEdit(this);
    line_phone=new QLineEdit(this);

    radio_man=new QRadioButton(this);
    radio_woman=new QRadioButton(this);

    button_submit=new QPushButton(this);


    label_name->setText("姓名");
    label_name->setGeometry(100,100,50,50);
    label_password->setText("密码");
    label_password->setGeometry(100,150,50,50);
    label_sex->setText("性别");
    label_sex->setGeometry(100,200,50,50);
    label_phone->setText("电话");
    label_phone->setGeometry(100,250,50,50);

    line_name->setGeometry(200,100,300,40);
    line_password->setGeometry(200,150,300,40);
    radio_man->setText("男");
    radio_man->setGeometry(250,200,100,40);
    radio_woman->setText("女");
    radio_woman->setGeometry(350,200,100,40);
    line_phone->setGeometry(200,250,300,40);

    button_submit->setText("提交");
    button_submit->setGeometry(300,300,100,50);
}

void Widget::handler()
{
    QString gender;
    //获取性别信息
    if(radio_man->isChecked()==true)
    {
        //男 被选中
        gender="男";
    }
    else
    {
        gender="女";
    }
    qDebug()<<"姓名:"<<line_name->text()
            <<"\n密码:"<<line_password->text()
            <<"\n性别:"<<gender
            <<"\n电话:"<<line_phone->text();
}

